package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.prd.model.OaCompeteInsideDO;
import com.prd.mapper.OaCompeteInsideMapper;
import com.prd.service.OaCompeteInsideService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;

/**
 * <p>
 * 内部竞聘详情数据表 服务实现类
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-29
 */
@Service
public class OaCompeteInsideServiceImpl extends ServiceImpl<OaCompeteInsideMapper, OaCompeteInsideDO> implements OaCompeteInsideService {


    @Autowired
    private OaCompeteInsideMapper competeInsideMapper;


    /**
     * 获取内部竞聘列表
     * @return
     */
    @Override
    public JsonData getList() {
        return JsonData.buildSuccess(competeInsideMapper.selectList(new QueryWrapper<>()));
    }

    /**
     * 根据id获取竞聘详情
     * @param id
     * @return
     */
    @Override
    public JsonData getDetailById(Long id) {
        return JsonData.buildSuccess(competeInsideMapper.selectById(id));
    }

    /**
     * 获取内部竞聘分页列表
     * @param date
     * @param type
     * @param size
     * @param page
     * @return
     */
    @Override
    public JsonData getPage(Date date, Integer type, Integer size, Integer page) {

        Page<OaCompeteInsideDO> doPage = new Page<>(size,page);
        LambdaQueryWrapper<OaCompeteInsideDO> wrapper = new LambdaQueryWrapper<>();
        if (date != null) {
            wrapper.eq(OaCompeteInsideDO::getStartTime, date);
        }
        if (type != null) {
            wrapper.eq(OaCompeteInsideDO::getAppiontType, type);
        }
        Page<OaCompeteInsideDO> insideDOPage = competeInsideMapper.selectPage(doPage, wrapper);

        HashMap<String, Object> resultMap = new HashMap<>(3);
        resultMap.put("total",insideDOPage.getTotal());
        resultMap.put("pages",insideDOPage.getPages());
        resultMap.put("data",insideDOPage.getRecords());

        return JsonData.buildSuccess(resultMap);
    }
}
